package com.daoliuhe.scaffold.web.controller.admin;

import com.daoliuhe.scaffold.model.ListEntry;
import com.daoliuhe.scaffold.service.ListEntryService;
import com.daoliuhe.scaffold.tools.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/listEntry")
public class ListEntryController {
	
	private static final Logger logger = LoggerFactory.getLogger(ListEntryController.class);
	
	@Autowired
	ListEntryService listEntryService;

	@RequestMapping("/getChildOneLevelData")
	@ResponseBody
	public Object getChildOneLevelData(ListEntry entity) {
		logger.info("getChildOneLevelData,entity:{}",entity);
		return listEntryService.getChildOneLevelData(entity);
	}
	
	@RequestMapping("/data")
	@ResponseBody
	public Object getPageData(ListEntry entity) {
		logger.info("getPageData,entity:{}",entity);
		return listEntryService.getPageData(entity);
	}

	@RequestMapping("/enabledData")
	@ResponseBody
	public Object getEnabledPageData(ListEntry entity) {
		logger.info("getPageData,entity:{}",entity);
		entity.setEnabled(Constants.ENABLE);
		return listEntryService.getPageData(entity);
	}
	
	@RequestMapping("/allData")
	@ResponseBody
	public Object getAllData(ListEntry entity) {
		logger.info("getPageData,entity:{}",entity);
		return listEntryService.getAllData(entity);
	}
	
	@RequestMapping("/selectTreeData")
	@ResponseBody
	public Object selectTreeData(ListEntry entity) {
		logger.info("selectTreeData,entity:{}",entity);
		return listEntryService.selectTreeData(entity);
	}
	
	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public Object saveOrUpdate(ListEntry entity) {
		logger.info("saveOrUpdate,entity:{}",entity);
		return listEntryService.saveOrUpdate(entity);
	}
	
	@RequestMapping("/saveOrUpdateNode")
	@ResponseBody
	public Object saveOrUpdateNode(ListEntry entity) {
		logger.info("saveOrUpdateNode,entity:{}",entity);
		return listEntryService.saveOrUpdateNode(entity);
	}
	
	/**
	 * 批量导入列表值
	 * @param listId
	 * @param parentId
	 * @param entryValues
	 * @return
	 */
	@RequestMapping("/saveBatchValues")
	@ResponseBody
	public Object saveBatchValues(String listId, String parentId, String entryValues, String listNameApi) {
		logger.info("saveBatchValues,listId:{},parentId:{},entryValues:{},listNameApi:{}"
				,listId,parentId,entryValues,listNameApi);
		return listEntryService.saveBatchValues(listId, parentId, entryValues, listNameApi);
	}
}
